package cn.alibab.inspect.service.impl;


import cn.alibab.common.model.PageBean;
import cn.alibab.common.model.PageResult;
import cn.alibab.common.model.R;
import cn.alibab.common.service.BaseService;
import cn.alibab.inspect.mapper.Inspection_PlanMapper;
import cn.alibab.inspect.model.Inspection_Plan;
import cn.alibab.inspect.model.Inspection_PlanExample;
import cn.alibab.inspect.service.InspectionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author LHW
 * @create 2020-07-10 17:24
 */
@Service
public class InspectionServiceImpl extends BaseService implements InspectionService {
    private final Inspection_PlanMapper inspection_planMapper;

    public InspectionServiceImpl(Inspection_PlanMapper inspection_planMapper) {
        this.inspection_planMapper = inspection_planMapper;
    }

    @Override
    public R selAll(String inspector , PageBean pageBean) {
        Inspection_PlanExample example = new Inspection_PlanExample();
        Inspection_PlanExample.Criteria criteria =example.createCriteria().andIdGreaterThanOrEqualTo(1);
        if (!StringUtils.isEmpty(inspector)) {
            criteria.andInspectorLike("%" + inspector + "%");
        }
        PageHelper.startPage(pageBean.getPage(),pageBean.getSize());
        PageInfo<Inspection_Plan> info=new PageInfo<>(inspection_planMapper.selectByExample(example));
        return R.ok(new PageResult<Inspection_Plan>(info.getTotal(),info.getList()));
    }


//    @Override
//    public R editUser(Inspection_Plan ins) {
//       Inspection_Plan inspection_plan  = inspection_planMapper.selectByPrimaryKey(ins.getId());
//        if (!(ins.getInspector().equals(ins.getInspector()))) {
//            if (isInsExist(ins.getInspector())) {
//                return R.error(RCode.USER_NAME_REPEAT);
//            }
//        }
//        ins.setInspectionMaterialDivision(null);
//        inspection_planMapper.updateByPrimaryKeySelective(ins);
//        return R.ok();
//    }

//    private Boolean isInsExist(String inspector) {
//        SysUserExample example = new SysUserExample();
//        example.createCriteria().andIsdelEqualTo(false).andUsernameEqualTo(inspector);
//        List<Inspection_Plan> sysUsers = inspection_planMapper.selectByExample(example);
//        if (sysUsers != null && sysUsers.size() > 0) {
//            return true;
//        }
//        return false;
//    }

}
